// 将所有的请求统一管理

let Router = require('koa-router');

let router = new Router();

let routerConfig = require('./router-config.js');


//策略模式
routerConfig.map(item => {
  let cb = item.method.toUpperCase() === 'GET' ? router.get : router.post;
  if (Array.isArray(item.callback)) {
    cb.call(router, item.url, ...item.callback);
    //router.get(url,xxx,function())
  } else {
    cb.call(router, item.url, item.callback);
  }
});

module.exports = router;
